package LC_0215;

/**
 * @author Jimmy Zhan WORKSTATION
 * @since 2023/7/12 11:16
 * 说明：找数组中第k大的元素 —— 笨比方法，暴力排序，然后返回数组的倒数第k个元素即可
 */

public class Viot {
    public static void main(String[] args) {
        Viot m = new Viot();
        System.out.println(m.findKthLargest(new int[]{3, 2, 1, 5, 6, 4}, 2));
    }

    public int findKthLargest(int[] nums, int k) {
        if (nums.length == 0 || nums == null) return 0;
        if (nums.length == 1) return nums[0];
        bubbleSort(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + "\t");
        }
        return nums[nums.length - k];
    }

    private void bubbleSort(int[] nums){
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] > nums[j]) {
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
            }
        }
    }

    public void swap(int i, int j) {
        int temp = i;
        i = j;
        j = temp;
    }
}


